package 力扣日常刷题.木23一月.第08天308;

import java.util.ArrayList;

/**
 * @author 帅小伙
 * @date 2022/3/8
 * @description
 */
public class Demo24和为s的连续正数序列 {


    public static void main(String[] args) {
        findContinuousSequence(9);
    }

    public static int[][] findContinuousSequence(int target) {
        ArrayList<int[]> ans = new ArrayList<>();
        int l = 1,r = 2;
        while(l < r) {
            int sum = (l + r) *(r - l + 1)/2;
            if(sum == target) {
                int[] arr = new int[r - l + 1];
                for (int k = l; k <= r; k++) {
                    arr[k - l] = k;
                }
                ans.add(arr);
                l++;
            }else if(sum < target) {
                r++;
            }else {
                l--;
            }
        }
        System.out.println();
        return ans.toArray(new int[ans.size()][]);
    }

}
